package Service;

import DAO.UserDAO;
import Utils.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService
{
    @Autowired
    private UserDAO userDAO;
    public Boolean Add_User(User user)
    {
        try{
            user.setUserID(String.valueOf(System.currentTimeMillis()+(int)(Math.random()*99999)));
            userDAO.Add_User(user);
            return true;
        }
        catch (Exception e)
        {
            return false;
        }
    }
    public User Get_UserByUserName(String UserName)
    {
        User user = null;
        try {
            user = userDAO.Get_UserByUserName(UserName);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        finally {
            return user;
        }
    }
    public User Get_UserByUserId(String UserId)
    {
        User user = null;
        try {
            user = userDAO.Get_UserByUserId(UserId);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        finally {
            return user;
        }
    }
    public Boolean Change_Password(String UserId,String Password)
    {
        Boolean status = false;
        try {
            userDAO.Update_User(UserId,Password);
            status = true;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        finally {
            return status;
        }
    }
}
